package com.linjj.seckill.service.impl;

import com.linjj.seckill.mapper.GoodsMapper;
import com.linjj.seckill.service.IGoodsService;
import com.linjj.seckill.vo.SeckillGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class GoodsService implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public List<SeckillGoodsVo> seckillList() {
        return goodsMapper.querySeckills();
    }

    @Override
    public List<SeckillGoodsVo> notStartList() {
        return goodsMapper.queryNotStartSeckills();
    }

    @Override
    public List<SeckillGoodsVo> startedList() {
        return goodsMapper.queryStartedSeckills();
    }

    @Override
    public List<SeckillGoodsVo> overList() {
        return goodsMapper.queryOverSeckills();
    }

    @Override
    public SeckillGoodsVo getSeckillVoByGoodsId(long goodsId) {
        return goodsMapper.querySeckill(goodsId);
    }
    @Transactional
    @Override
    public boolean reduceStock(long goodsId) {
        int ret0 = goodsMapper.reduceGoodsStock(goodsId);
        int ret1 = goodsMapper.reduceSeckillStock(goodsId);
        return ret0==ret1&&ret1>0;
    }
}
